package com.lizhen.structurepattern.filterpattern.impl;

import com.lizhen.structurepattern.filterpattern.Criteria;
import com.lizhen.structurepattern.filterpattern.Person;

import java.util.Iterator;
import java.util.List;

public class OrCriteria implements Criteria {
    private Criteria criteria;
    private Criteria otherCriteria;

    public OrCriteria(Criteria criteria, Criteria otherCriteria) {
        this.criteria = criteria;
        this.otherCriteria = otherCriteria;
    }

    public List<Person> meetCriteria(List<Person> persons) {
        List<Person> firstCriteriaItems = this.criteria.meetCriteria(persons);
        List<Person> otherCriteriaItems = this.otherCriteria.meetCriteria(persons);
        Iterator var5 = otherCriteriaItems.iterator();

        while (var5.hasNext()) {
            Person person = (Person) var5.next();
            if (!firstCriteriaItems.contains(person)) {
                firstCriteriaItems.add(person);
            }
        }

        return firstCriteriaItems;
    }
}
